package com.lanou.list;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author zyj
 * @date 2022年05月19日 14:22
 */
public class ArrayListDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("张三");
        list.add("李四");
        list.add("王五");
        list.add("张无忌");
        list.add("张三");

        List<String> list1 = new ArrayList<>();
        list.add("张三1");
        list.add("李四1");
        list.add("王五1");
        list.add("张无忌1");
        list.addAll(list1);

        System.out.println(list.isEmpty());
        System.out.println(list.contains("张三"));
        List<String> list2 = new ArrayList<>();
        list2.add("张三");
        list2.add("李四1");
        list2.add("王五1");
        list2.add("张无忌1");

        list.removeAll(list2);


        System.out.println(list.set(0, "小黄"));
        System.out.println(list.indexOf("李四"));
        System.out.println("遍历集合");
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + "\t");
        }
        System.out.println();

        for (String s:list) {
            System.out.print(s + "\t");
        }
        System.out.println();

        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            System.out.print(iterator.next() + "\t");
        }
        System.out.println();

        // lambda表达式
        list.stream().forEach(System.out::print);
        System.out.println();
        list.stream().distinct().forEach(System.out::print);
        System.out.println();
        list.stream().distinct().filter(name->name.startsWith("张")).forEach(System.out::print);

        list.stream().distinct().forEach(s -> {
        });
        Comparable c = new Comparable(){

            @Override
            public int compareTo(Object o) {
                return 0;
            }
        };


        Comparable c1 = (o) ->{
            return 1;
        };

    }
}
